package com.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.entity.User;

@Repository
public class UserDaoImpl extends HibernateDaoSupport implements UserDao{
	
	@Resource
	public void setSf(SessionFactory sf) {
		super.setSessionFactory(sf);
	}
	
	
	
	@Override
	public List<User> findAll() {
		String hql = "from User";
		return (List<User>) getHibernateTemplate().find(hql);
	}

	@Override
	public User findById(Integer id) {
		
		return getHibernateTemplate().get(User.class, id);
	}

	@Override
	public void save(User user) {
		getHibernateTemplate().save(user);	
	}

	@Override
	public void update(User user) {
		getHibernateTemplate().update(user);		
	}

	@Override
	public void delete(Integer id) {
		
		User user = new User();
		user.setId(id);
		getHibernateTemplate().delete(user);
	}
	
}
